
snippet py-catch "python catch decorator"
	`PkgLoadSnip('python/catch.py')`

snippet py-singleton "python singleton decorator"
	`PkgLoadSnip('python/singleton.py')`

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ReStructuredText docstring style for python
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
snippet pfunc "python function"
	"""${0:rst}
	Parameters:

	Returns:

	Raises:

	Examples:
	"""

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# python's code snippets of python modules
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
snippet mpl "matplotlib for python"
	from matplotlib.backend_bases import KeyEvent
	import matplotlib.pyplot as plt

	def on_key(event:KeyEvent):
		if event.key == 'escape':
			plt.close()

	fig = plt.figure('Plot')
	fig.canvas.mpl_connect('key_press_event', on_key)
	# fig.subplots_adjust(0.1, 0.1, 1.0, 1.0, 0.1, 0.05)
	# ax = fig.add_subplot(1, 1, 1)
	# ax = fig.add_axes((0.1, 0.1, 0.8, 0.8))
	# ax.plot()
	plt.show()
	${0}

snippet mplt "matplotlib.pyplot for python"
	from matplotlib.backend_bases import KeyEvent
	import matplotlib.pyplot as plt

	def on_key(event:KeyEvent):
		if event.key == 'escape':
			plt.close()

	plt.figure('Plot')
	plt.connect('key_press_event', on_key)
	# plt.subplots_adjust(0.1, 0.1, 1.0, 1.0, 0.1, 0.05)
	# plt.subplot(1, 1, 1)
	# plt.axes((0.1, 0.1, 0.8, 0.8))
	# plt.plot()
	plt.show()
	${0}

snippet mpl3d "matplotlib 3d for python"
	import mpl_toolkits.mplot3d as plt3d

	#ax = fig.add_subplot(111, projection='3d')
	#ax.plot_wireframe(x, y, z)
	#x, y = np.meshgrid(np.linespace(), np.arange())
	#ax.plot_surface(x, y, z, shade=True, cmap='jet')

snippet mplcoord "matplotlib format_coord for imshow"
	def get_format_coord(img):
		def format_coord(x, y):
			col = round(x)
			row = round(y)
			nrows, ncols = img.shape[:2]
			if 0 <= col < ncols and 0 <= row < nrows:
				z = str(img[row, col])
				return f'({x:1.2f}, {y:1.2f}) : {z}'
			else:
				return f'({x:1.2f}, {y:1.2f})'
		return format_coord
	plt.gca().format_coord = get_format_coord(img)
	ax.format_coord = get_format_coord(img)

snippet mgif "pymovie make gif"
	import moviepy.editor as mpy
	from moviepy.video.io.bindings import mplfig_to_npimage

	def make_frame(t):
		return mplfig_to_npimage(fig)

	anim = mpy.VideoClip(make_frame, duration=1)
	anim.write_videofile("m.mp4", fps=24)
	anim.write_gif("m.gif", fps=24)
